import requests
import json
import pandas as pd
cargo_text_now_url = r"http://qa-nlp.amh-group.com/paoding/text_cargo_now"

def get_result(text):
    packageType = ""
    header = {
        'Content-Type': "application/json"
    }
    post_data = {
        'sentence': text
    }

    try:
        req = requests.post(cargo_text_now_url, data=json.dumps(post_data), headers=header)
        if req.json():
            packageType = req.json()['data']['packageType']
    except Exception as e:
        pass
    return packageType



if __name__ == '__main__':
    df = pd.read_excel("包装其他vs服务备注_220109.xlsx")
    df = df[:1000]
    df['cargo_name_result'] = df['cargo_name'].apply(get_result)
    df['服务备注_result'] = df['服务备注'].apply(get_result)
    df['packing_type_result'] = df['packing_type'].apply(get_result)
    print(df.head())
    df.to_excel("包装其他vs服务备注_220109_result_1000.xlsx")
